package app

import (
	"fmt"
	"os"
)

var dbg bool

func New(cmdOpts ...ApplyOption) *Command {
	c := &Command{}
	c.Flags().SortFlags = false
	Apply(c, cmdOpts...)
	//c.Flags().BoolP("help", "h", false, "print usage.")
	return c
}

func SetDebug(debug bool) {
	dbg = debug
}

func CheckExit(err error, printStack ...bool) {
	if err != nil {
		if dbg || (len(printStack) > 0 && printStack[0]) {
			fmt.Printf("%+v\n", err)
		} else {
			fmt.Printf("%v\n", err)
		}
		os.Exit(-1)
	}
}
